package com.atguigu.lease.admin.controller.room;

import com.atguigu.lease.admin.service.RoomInfoService;
import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.bean.RoomInfo;
import com.atguigu.lease.model.vo.RoomDetailVo;
import com.atguigu.lease.model.vo.RoomItemVo;
import com.atguigu.lease.model.vo.RoomQueryVo;
import com.atguigu.lease.model.vo.RoomSubmitVo;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LOGIN
 * @title RoomController
 * @create 2025/6/26 15:22
 * @description
 */
@Schema(description = "房间管理模块")
@RestController
@RequestMapping("/admin/room")
public class RoomController {
    @Autowired
    private RoomInfoService roomInfoService;
//    /admin/room/listBasicByApartmentId?id=9
    @Operation(summary = "5、根据公寓id查询房间列表")
    @GetMapping("/listBasicByApartmentId")
    public Result listBasicByApartmentId(@RequestParam Long id){
        List<RoomInfo> roomInfos = roomInfoService.listBasicByApartmentId(id);
        return Result.ok(roomInfos);
    }

    //    /admin/room/updateReleaseStatusById?id=9&status=0
    @Operation(summary = "4、更新房间发布状态")
    @PostMapping("/updateReleaseStatusById")
    public Result updateReleaseStatusById(@RequestParam Long id,
                                          @RequestParam String status ){
        roomInfoService.update(Wrappers.lambdaUpdate(RoomInfo.class)
                .eq(RoomInfo::getId,id) //查找要修改状态记录对应的id
                .set(RoomInfo::getIsRelease,status)); //修改状态
        return Result.ok();
    }

//    /admin/room/removeById
    @Operation(summary = "3、删除房间")
    @DeleteMapping("/removeById")
    public Result removeById(@RequestParam Long id){
        roomInfoService.deleteRoomById(id);
        return Result.ok();
    }

// /admin/room/getDetailById?id=9
    @Operation(summary = "3、根据id查询房间详情")
    @GetMapping("/getDetailById")
    public Result<RoomDetailVo> getDetailById(@RequestParam(value="id",required = true) Long id){

        return Result.ok(roomInfoService.getDetailById(id));
    }

// /admin/room/pageItem?current=1&size=10
    @Operation(summary = "2、根据条件分页查询房间列表")
    @GetMapping("/pageItem")
    public Result<Page<RoomItemVo>> Item(@RequestParam Long current, @RequestParam Long size, RoomQueryVo roomQueryVo){

        Page<RoomItemVo> page = roomInfoService.getPageItem(current,size,roomQueryVo);
        return Result.ok(page);
    }

    @Operation(summary = "1、新增更新房间信息")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody RoomSubmitVo roomSubmitVo){
            roomInfoService.saveOrUpdateRoomSubmitVo(roomSubmitVo);
            return Result.ok();
    }
}
